package com.gt.ao.test;

import com.sun.xml.internal.messaging.saaj.util.ByteOutputStream;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.regex.Pattern;

public class Main {

    public static void main(String[] args) {
        System.out.println(100000/1000);
        System.out.println(100001/1000);
        System.out.println(new BigDecimal(100001).divide(new BigDecimal(1000)));
        System.out.println(Math.round(100001/1000));
        System.out.println(Math.floor(100001/1000));
        System.out.println(Math.rint(100001/1000));
        double d = 100001*1.0/1000;
        System.out.println(Double.valueOf(Math.ceil(d)).intValue());
        System.out.println((1024+"|"+1024+",").getBytes().length);


        String jarName = "Txqr-512.jar";
        if(jarName.indexOf("Txqr")!=-1&&jarName.indexOf("-")!=-1){
            String val = jarName.split("\\.")[0].split("-")[1];
            System.out.println(val);
        }


        double ddd = 1d/100d*100d;
        System.out.println(ddd);


        System.out.println("123abc".substring("123".length(),5));

        byte[] charb = null;
        String s = null;
        try {
            charb = "123|你好吗，我很好|abc".getBytes("utf-8");
            s = new String(charb,"iso-8859-1");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        try {
            charb = s.getBytes("iso-8859-1");
            System.out.println(new String(charb,"utf-8"));
            System.out.println("和".getBytes(StandardCharsets.UTF_8).length);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

//        File file = new File("/yunrong/transfile/");
//        if(!file.exists()){
//            file.mkdirs();
//        }
        byte[][] bytes = new byte[10][];
        System.out.println(bytes.length);

        /*try(FileInputStream fis = new FileInputStream("/Users/gt.ao/Desktop/a.txt");
        FileOutputStream fos = new FileOutputStream("/Users/gt.ao/Desktop/a_copy.txt")){
            byte[] b = new byte[fis.available()];
            fis.read(b);
            fos.write(b);
            fis.close();fos.close();
        }catch (Exception e){
            e.printStackTrace();
        }*/

       /* byte[] bbb = new byte[]{67, 55, -105, 35, -94, -14, -13, 7, -61, 23, -58, 22, 22, 18, -25, 71, -121, 66, -58, 118, 22, -9, 70, 22, -13, 19, 35, 54, 22, 38, 52, 3, 19, 99, 50, -26, 54, -10, -34, -102, -71, -114, 107, 105, -66, -5, -56, 30, -5, -55, -14, -14, -16, -20, 17};
        try {
            System.out.println(Arrays.toString(new String(bbb,"ISO-8859-1").getBytes(StandardCharsets.ISO_8859_1)));
            System.out.println(Arrays.toString("yr://gaotao123abc@163.com高涛！？//".getBytes()));

            System.out.println("-----------------");
            String chars = "哈哈，再见";
            System.out.println(Arrays.toString(chars.getBytes(StandardCharsets.UTF_8)));
            System.out.println(Arrays.toString(chars.getBytes(StandardCharsets.ISO_8859_1)));
            System.out.println(Arrays.toString(chars.getBytes("GBK")));
            System.out.println("-----------------");
            System.out.println(new String(chars.getBytes(StandardCharsets.UTF_8),"utf-8"));
            System.out.println(new String(chars.getBytes(StandardCharsets.ISO_8859_1),StandardCharsets.ISO_8859_1));
            System.out.println(new String(chars.getBytes("GBK"),"GBK"));

            System.out.println(5/3);
            System.out.println(10000010/1024);
            System.out.println("测试文件base64后转iso--------------------");
            File file = new File("/Users/gt.ao/Desktop/WechatIMG2.jpeg");
            try (FileInputStream fis = new FileInputStream(file); ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();FileOutputStream fos = new FileOutputStream("/Users/gt.ao/Desktop/111.jpeg")){

                int len = 0;
                byte[] bb = new byte[1024];
                byte[][] allbb = new byte[(fis.available()/bb.length+1)][];
                System.out.println(fis.available());
                int dex=0;
                int lll = 0;
                while((len = fis.read(bb))!=-1){
                    lll+=len;
                    dex++;
                    byteOutputStream.write(bb,0,len);
                }
                byte[] bosBytes = byteOutputStream.toByteArray();
                byte[] tb = ("yr://0|"+(1)+"|123456,").getBytes(StandardCharsets.ISO_8859_1);
                System.out.println(tb.length);
                byte[] bbaabb = addTwoArray(tb,bosBytes);
                System.out.println(bbaabb.length);

                String ds = new String(bbaabb,StandardCharsets.ISO_8859_1);
                //System.out.println(ds);
                String saa = ds.substring(ds.indexOf(",")+1);
                //System.out.println(saa);
                byte[] bbaaa = saa.getBytes(StandardCharsets.ISO_8859_1);
                System.out.println(bbaaa.length);
                //System.out.println(new String(bbaaa,"ISO-8859-1"));
                fos.write(bbaaa);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }*/

        Map<Integer,String> m = new HashMap<>(32);
        m.put(1,"");
        m.put(12,"");
        System.out.println(m.keySet().toString());


        int total = 20;
        List<String> list = Arrays.asList(new String[]{"0","1","2","4","18","19","20"});
        StringBuffer sb = new StringBuffer();
        for(int i=0;i<total;i++){
            if(!list.contains(i+"")){
                sb.append("(").append(i).append(")");
                if(i<(total-1)){
                    sb.append(",");
                }
            }
        }
        System.out.println(sb.toString());


        SortedMap<Integer,byte[]> sortedMap = Collections.synchronizedSortedMap(new TreeMap<>());
        sortedMap.put(0,"0".getBytes(StandardCharsets.UTF_8));
        sortedMap.put(1,"1".getBytes(StandardCharsets.UTF_8));
        System.out.println(sortedMap);
    }

    public static byte[] addTwoArray(byte[] btX, byte[] btY){
        //定义目标数组  目标数组应该等于将要拼接的两个数组的总长度
        byte[] btZ = new byte[btX.length + btY.length];

        System.arraycopy(btX, 0, btZ, 0, btX.length);
        System.arraycopy(btY, 0, btZ, btX.length, btY.length);
        return btZ;
    }

    private static boolean isNumber(String string) {
        if (string == null){
            return false;
        }
        Pattern pattern = Pattern.compile("^-?\\d+(\\.\\d+)?$");
        return pattern.matcher(string).matches();
    }

    // 生成文件
    public File makeFilePath(String filePath, String fileName) {
        File file = null;
        makeRootDirectory(filePath);
        try {
            file = new File(filePath + fileName);
            if (!file.exists()) {
                file.createNewFile();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return file;
    }

    // 生成文件夹
    public static void makeRootDirectory(String filePath) {
        File file = null;
        try {
            file = new File(filePath);
            if (!file.exists()) {
                file.mkdirs();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
